package com.elsa.common.handler;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.http.MediaType;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;

import com.elsa.common.entity.ElsaResponse;
import com.elsa.common.utils.ElsaUtil;

/**
 * @projectName：elsa-common
 * @typeName：ElsaAccessDeniedHandler
 * @author：cos
 * @date：2021年5月11日
 * @version
 * @desc：资源服务器异常翻译器：用户无权限返回403
 */
public class ElsaAccessDeniedHandler implements AccessDeniedHandler {

    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException {
        ElsaResponse elsaResponse = new ElsaResponse();
        ElsaUtil.makeResponse(
                response, MediaType.APPLICATION_JSON_UTF8_VALUE,
                HttpServletResponse.SC_FORBIDDEN, elsaResponse.message("没有权限访问该资源"));
    }
}
